﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace NoFake.IO
{
    /// <summary>
    /// File
    /// </summary>
    public class NFile : IDisposable
    {
        /// <summary>
        /// Full path to file
        /// </summary>
        public  string FullPath { get; set; }

        /// <summary>
        /// Name of the file
        /// </summary>
        /// <value>
        /// The name of the file.
        /// </value>
        public string FileName { get; set; }

        /// <summary>
        /// Occurs when file is deletes.
        /// </summary>
        public event EventHandler FileDeleted = delegate { };

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Disposing();
            FileDeleted(this, EventArgs.Empty);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Disposings this instance.
        /// </summary>
        /// <exception cref="System.NotImplementedException"></exception>
        protected virtual void Disposing()
        {
        }

         /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public NFile(string fileName)
        {
            Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(fileName), "FileName is empty");
            Contract.Requires<ArgumentException>(!Path.IsPathRooted(fileName), "FileName can't be a rooted path");

             FileName = fileName;
        }

        /// <summary>
        /// Finalizes an instance of the <see cref="NFile"/> class.
        /// </summary>
        ~NFile()
        {
            Disposing();
        }
    }
}